package com.yuanlrc.base.entity.admin;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.persistence.criteria.CriteriaBuilder;
import java.util.Date;

/**
 * 借阅管理实体类
 */
@Entity
@Table(name="ylrc_borrow")
@EntityListeners(AuditingEntityListener.class)
public class Borrow {

    private static final long serialVersionUID = 1L;

    @Column(name="id",nullable=false,length=11)
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Id
    private Long id;//唯一id

    @Column(name="borrow_time",nullable=false)
    @CreatedDate
    private Date borrowTime;//借出时间

    @Column(name = "borrow_num",nullable = false)
    private Integer borrowNum;//用户借阅数量

    @JsonFormat(pattern = "yyyy-MM-dd")
    @Column(name="expected_return_time",nullable=false)
    private Date expectedReturnTime;//预计归还时间

    @Column(name = "borrow_state",nullable = false)
    private Integer borrowState;//借还状态 0借阅中  1已归还

    @Column(name="return_time",nullable=true)
    private Date returnTime;//归还时间

    @Column(name = "over_time",nullable = false)
    private Integer overTime;//是否逾期  1已逾期  0未逾期

    @ManyToOne
    @JoinColumn(name = "student_id")
    private Student student;//借阅列表 学生类对象

    @ManyToOne
    @JoinColumn(name = "book_id")
    private Book book;//借阅列表 图书类对象

    @Column(name = "book_name",nullable = true)
    private String bookName;

    @Column(name = "student_name",nullable = true)
    private String studentName;

    public Borrow(Date borrowTime, Integer borrowNum, Date expectedReturnTime, Integer borrowState, Date returnTime, Integer overTime, Student student, Book book, String bookName) {
        this.borrowTime = borrowTime;
        this.borrowNum = borrowNum;
        this.expectedReturnTime = expectedReturnTime;
        this.borrowState = borrowState;
        this.returnTime = returnTime;
        this.overTime = overTime;
        this.student = student;
        this.book = book;
        this.bookName = bookName;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getBorrowTime() {
        return borrowTime;
    }

    public void setBorrowTime(Date borrowTime) {
        this.borrowTime = borrowTime;
    }

    public Integer getBorrowNum() {
        return borrowNum;
    }

    public void setBorrowNum(Integer borrowNum) {
        this.borrowNum = borrowNum;
    }

    public Date getExpectedReturnTime() {
        return expectedReturnTime;
    }

    public void setExpectedReturnTime(Date expectedReturnTime) {
        this.expectedReturnTime = expectedReturnTime;
    }

    public Integer getBorrowState() {
        return borrowState;
    }

    public void setBorrowState(Integer borrowState) {
        this.borrowState = borrowState;
    }

    public Date getReturnTime() {
        return returnTime;
    }

    public void setReturnTime(Date returnTime) {
        this.returnTime = returnTime;
    }

    public Integer getOverTime() {
        return overTime;
    }

    public void setOverTime(Integer overTime) {
        this.overTime = overTime;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public Book getBook() {
        return book;
    }

    public void setBook(Book book) {
        this.book = book;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public Borrow() {
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    @Override
    public String toString() {
        return "Borrow{" +
                "id=" + id +
                ", borrowTime=" + borrowTime +
                ", borrowNum=" + borrowNum +
                ", expectedReturnTime=" + expectedReturnTime +
                ", borrowState=" + borrowState +
                ", returnTime=" + returnTime +
                ", overTime=" + overTime +
                ", student=" + student +
                ", book=" + book +
                ", bookName='" + bookName + '\'' +
                '}';
    }
}
